package com.splic.common.utils;

public class MathUtils {

    public static String randomDigitNumber(int length) {
        int start = Integer.parseInt(makeUpNewData("", length));
        int end = Integer.parseInt(makeUpNewData("", length + 1)) - start;
        return (int)(Math.random() * (double)end) + start + "";
    }

    public static String makeUpNewData(String target, int length) {
        return makeUpNewData(target, length, "0");
    }

    public static String makeUpNewData(String target, int length, String add) {
        if (target.startsWith("-")) {
            target.replace("-", "");
        }

        if (target.length() >= length) {
            return target.substring(0, length);
        } else {
            StringBuffer sb = new StringBuffer("1");

            for(int i = 0; i < length - (1 + target.length()); ++i) {
                sb.append(add);
            }

            return sb.append(target).toString();
        }
    }
}
